// Created by Joe on 2017/6/15.

app.directive(
    'charMask',
    function () {
        return {
            restrict: 'A',
            scope: {
                prefix: '=',
                postfix: '=',
                info: '='
            },
            link: function (scope, ele, attr) {
                var fix = attr.fix || '';
                scope.info = scope.info || '';
                // stb not support
                // ele.text(fix + scope.info.substring(0, scope.start) +
                //     Array.apply(null, {length: scope.num}).map(function () {return '*';}).join('') +
                //     scope.info.substr(scope.start + scope.num));
                var maskLen = scope.info.length - scope.prefix - scope.postfix;
                var prefixText = scope.info.substr(0, scope.prefix);
                var maskText = '';
                for (var i = 0; i < maskLen; i++) {
                    maskText += '*';
                }
                var postfixText = scope.postfix === 0 ? '' : scope.info.substr(scope.prefix + maskLen);

                ele.text(fix + prefixText + maskText + postfixText);
            }
        };
    }
);